<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button @click="str = 'Child1'">child1</button>
      <button @click="str = 'Child2'">child2</button>
      <button @click="str = 'Child3'">child3</button>
      <!-- <child1 v-if="num === 1"></child1>
      <child2 v-if="num === 2"></child2>
      <child3 v-if="num === 3"></child3> -->

      <!-- component就是用来做动态组件的, 必须要配合is属性 -->
      <!-- is属性写字符串，要和引进来的组件名称相同 -->
      <component :is="str"></component>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const Child1 = {
        template: `
          <div>child1组件</div>
        `,
      };
      const Child2 = {
        template: `
          <div>child2组件</div>
        `,
      };
      const Child3 = {
        template: `
          <div>child3组件</div>
        `,
      };
      new Vue({
        el: "#app",
        data: {
          num: 1,
          str: "Child1",
        },
        components: {
          Child1,
          Child2,
          Child3,
        },
      });
    </script>
  </body>
</html>
